//
//  RGPickerView.m
//  RedGrass
//
//  Created by wuyine on 2019/1/17.
//  Copyright © 2019年 hongcaosp. All rights reserved.
//

#import "RGPickerView.h"

@interface RGPickerView()
@property (nonatomic,strong)NSMutableArray *years;//
@property (nonatomic,strong)NSMutableArray *months;//
@property (nonatomic,strong)NSMutableArray *days;//
@end

@implementation RGPickerView

#pragma mark - 加载地址数据
- (void)loadAddressData{
}

#pragma mark - UIPickerDatasource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 3;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    
    if (0 == component) {
        return self.years.count;
    }
    else if (1 == component){
        return self.months.count;
    }
    else if (2 == component){
        return self.days.count;
    }
    return 0;
}

#pragma mark - UIPickerViewDelegate
#pragma mark 填充文字
- (NSString *)pickerView:(UIPickerView *)pickerView
             titleForRow:(NSInteger)row
            forComponent:(NSInteger)component{
    NSString *title;
    switch (component) {
        case 0:
            title = [self.years objectAtIndex:row];
            break;
        case 1:
            title = [self.months objectAtIndex:row];
            break;
        case 2:
            title = [self.days objectAtIndex:row];
            break;
        default:
            break;
    }
    return title;
}

- (void)sureBtnClicked{
    if ([self.delegate respondsToSelector:@selector(sureBtnClickReturnProvince:City:Area:)]) {
        NSInteger selectProvince = [self.addressPickerView selectedRowInComponent:0];
        NSInteger selectCity     = [self.addressPickerView selectedRowInComponent:1];
        NSInteger selectArea     = [self.addressPickerView selectedRowInComponent:2];
        
        [self.delegate sureBtnClickReturnProvince:[self.years objectAtIndex:selectProvince]
                                         City:[self.months objectAtIndex:selectCity]
                                         Area:[self.days objectAtIndex:selectArea]];
    }
}

- (NSMutableArray *)years {
    if (!_years) {
        _years = [NSMutableArray new];
        for (NSInteger i=1980; i<2019; i++) {
            [_years addObject:[NSString stringWithFormat:@"%d",i]];
        }
    }
    return _years;
}

- (NSMutableArray *)months {
    if (!_months) {
        _months = [NSMutableArray new];
        for (NSInteger i=1; i<=12; i++) {
            [_months addObject:[NSString stringWithFormat:@"%d",i]];
        }
    }
    return _months;
}

- (NSMutableArray *)days {
    if (!_days) {
        _days = [NSMutableArray new];
        for (NSInteger i=1; i<=31; i++) {
            [_days addObject:[NSString stringWithFormat:@"%d",i]];
        }
    }
    return _days;
}

@end
